package com.noreg.util;

import org.springframework.context.ApplicationContext;


/**
 * 
 * @author jeson.sha
 *
 */
public class BeanUtil {
	
	private static ApplicationContext ac ;
	
	public static ApplicationContext getAc() {
		return ac;
	}

	public static void setApplicationContext (ApplicationContext ac)
	{
//		WebApplicationContextUtils.getWebApplicationContext(sc);
		if (BeanUtil.ac==null)
			BeanUtil.ac = ac;
		
	}
	
	/**
	 * 得到SPRING容器中的BEAN实例
	 * @param beanName
	 * @return
	 */
	public static Object getBean (String beanName)
	{
		ApplicationContext tempAc =null;
		Object returnObj = null; 
		if (ac==null)
			return null;
		tempAc = ac;
		returnObj =  tempAc.getBean(beanName);
		if (returnObj==null)
		{
			while (tempAc!=null)
			{
				tempAc = ac.getParent();
				returnObj = tempAc.getBean(beanName);
			}
		}	
		
		return returnObj;
	}

}
